<?php

$n=new n_ini();

?>
<form action="" method="post">
	Host<br />
	<input type="text" name="host_m" class="input_style"/><br />
	Login<br />
	<input type="text" name="login_m" class="input_style"/><br />
	Haslo<br />
	<input type="password" name="pass_m" class="input_style"/><br />
	Port<br />
	<input type="text" name="port_m" class="input_style"/><br />
	Protokół bezpieczeństwa<br />
	<select name="smtpsec_m">
		<option value='tls'>TLS</option>
		<option value='ssl'>SSL</option>
	</select><br />
	Podpis wiadomości<br />
	<input type="text" name="from_m" class="input_style"/><br />
	<input name="submit" type="submit" value="Zatwierdź i przetestuj" />
</form>

<?php 
	
if($_POST!=NULL){
	//print_r($_POST);
	$mail             = new PHPMailer();
	$body             = "test";
	$body             = eregi_replace("[\]",'',$body);
	$mail->IsSMTP(); // telling the class to use SMTP
	$mail->SMTPDebug  = 0;                     // enables SMTP debug information (for testing)
	$mail->SMTPAuth   = true;                  // enable SMTP authentication
	$mail->SMTPSecure = $_POST['smtpsec_m'];                 // sets the prefix to the servier
	$mail->Host       = $_POST['host_m'];      // sets GMAIL as the SMTP server
	$mail->Port       = $_POST['port_m'];                   // set the SMTP port for the GMAIL server
	$mail->Username   = $_POST['login_m'];  // GMAIL username
	$mail->Password   = $_POST['pass_m'];            // GMAIL password 
	$mail->SetFrom($_POST['login_m'], $_POST['from_m']);
	$mail->Subject    = "[TEST]Nyanya cms test";
	$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test*/
	$mail->MsgHTML($body); 
	$address = "nyanya.cms@gmail.com";
	$mail->AddAddress($address, "Nyanya"); 
	$efekt = $mail->Send();
	//echo $efekt;
	if(!$efekt) {
	echo "Błąd wysyłania wiadomości: " . $mail->ErrorInfo;
	} else {
            echo "Wiadomość wysłana!";
            $tab=Array ( 'config' => Array (
                                    'mail_user' => $_POST['login_m'], 
                                    'mail_port' => $_POST['port_m'],
                                    'mail_password' => $_POST['pass_m'],
                                    'mail_host' => $_POST['host_m'],
                                    'mail_ssl' => $_POST['smtpsec_m'],
				    'mail_from' => $_POST['from_m'],
				    'mail_ok' => 1
                                       ));
            $n->w2i($tab, "setup.ini",TRUE);
	}
		
}
$sini=parse_ini_file("setup.ini",1);
if($sini['config']['mail_ok'] == 1){
    echo '<form action="index.php?token='.md5($results[4]['file']).'" method="post" enctype="multipart/form-data" >';
    echo " <input type='submit' ".$str." value='dalej' /></form>";
}

?>
